package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowGoodsType;
import cn.stylefeng.guns.modular.manager.mapper.FlowGoodsTypeMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowGoodsTypeParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowGoodsTypeResult;
import  cn.stylefeng.guns.modular.manager.service.FlowGoodsTypeService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 物品分类 服务实现类
 * </p>
 *
 * @author yumker
 * @since 2021-01-07
 */
@Service
public class FlowGoodsTypeServiceImpl extends ServiceImpl<FlowGoodsTypeMapper, FlowGoodsType> implements FlowGoodsTypeService {

    @Override
    public void add(FlowGoodsTypeParam param){
        FlowGoodsType entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowGoodsTypeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowGoodsTypeParam param){
        FlowGoodsType oldEntity = getOldEntity(param);
        FlowGoodsType newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowGoodsTypeResult findBySpec(FlowGoodsTypeParam param){
        return null;
    }

    @Override
    public List<FlowGoodsTypeResult> findListBySpec(FlowGoodsTypeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowGoodsTypeParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowGoodsTypeParam param){
        return param.getGoodsTypeId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowGoodsType getOldEntity(FlowGoodsTypeParam param) {
        return this.getById(getKey(param));
    }

    private FlowGoodsType getEntity(FlowGoodsTypeParam param) {
        FlowGoodsType entity = new FlowGoodsType();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
